home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume15 / bootmenu / part02 < prev    next >
Encoding:
Text File  |  1990-12-16  |  30.4 KB  |  1,169 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: gwr@linus.mitre.org
  3. keywords: fdisk partition boot menu bootmenu pfdisk
  4. organization: The MITRE Corporation, Bedford, MA.
  5. summary: primary boot sector program with menu
  6. subject: v15i085: BOOTMENU and PFDISK 1.3 (part 2/2)
  7. from: gwr@linus.mitre.org
  8. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  9.  
  10. Posting-number: Volume 15, Issue 85
  11. Submitted-by: gwr@linus.mitre.org
  12. Archive-name: bootmenu/part02
  13.  
  14. Here is part 2 of the BOOTMENU and PFDISK 1.3 distribution.
  15.  
  16. See the README file at the beginning of part 1 for a general
  17. description of this package.  Program documentation for both
  18. BOOTMENU and PFDISK are at the beginning of the shar file below.
  19.  
  20. Gordon W. Ross  (M/S E095)    internet: gwr@linus.mitre.org
  21. The MITRE Corporation        uucp: {decvax|philabs}!linus!gwr
  22. Burlington Road              office phone: 617-271-3205
  23. Bedford, MA 01730 (U.S.A.)
  24.  
  25. #! /bin/sh
  26. # This is a shell archive, meaning:
  27. # 1. Remove everything above the #! /bin/sh line.
  28. # 2. Save the resulting text in a file.
  29. # 3. Execute the file with /bin/sh (not csh) to create the files:
  30. #    bootmenu.doc
  31. #    pfdisk.doc
  32. #    SStor.txt
  33. #    bootmenu.asm
  34. #    bootauto.asm
  35. #    asm2bin.bat
  36. #    make_msc.bat
  37. #    bootmenu.hex
  38. #    bootauto.hex
  39. #    hex2bin.c
  40. # This archive created: Tue Oct 23 13:53:20 1990
  41. # By:    Gordon W. Ross (The MITRE Corporation, Bedford, MA.)
  42. export PATH; PATH=/bin:$PATH
  43. echo shar: extracting "'bootmenu.doc'" '(3923 characters)'
  44. if test -f 'bootmenu.doc'
  45. then
  46.     echo shar: will not over-write existing file "'bootmenu.doc'"
  47. else
  48. cat << \SHAR_EOF > 'bootmenu.doc'
  49.  
  50.     BOOTMENU -- a BOOT sector program with a MENU
  51.     ---------------------------------------------
  52.         by Gordon W. Ross, Aug 1990
  53.  
  54.     This program is loaded by the PC ROM BIOS and is responsible
  55.     for selecting one of four partitions to boot from.  The normal
  56.     (MS-DOS) version of this program always boots the "active"
  57.     partition, but this version allows any partition to be
  58.     selected for booting, wether marked "active" or not.
  59.  
  60.     Two versions of this program are now distributed:
  61.  
  62.     BOOTMENU is small (less than 256 bytes of code) and compatible
  63.     with the SpeedStor hard disk formatting package.  (Note that
  64.     SpeedStor writes in several locations in the boot sector!)
  65.     This version, however, does not allow unattended reboots.
  66.     After BOOTMENU displays its partition menu, it waits
  67.     indefinitely for someone to select a boot partition.
  68.  
  69.     BOOTAUTO (previously called "boot-hdp") is a full-featured
  70.     boot program which allows boot-time partition selection, but
  71.     also provides a default selection which is used if no user
  72.     input arrives within five seconds.
  73.  
  74.     The behaviour of BOOTAUTO is as follows:
  75.  
  76.     BOOTAUTO displays the message:
  77.         Booting device: hd0,
  78.     and then pauses for a five second delay.
  79.  
  80.     If the user presses any key before the delay expires, a menu
  81.     of bootable partitions is displayed, and the user is prompted
  82.     for the number of the partition to boot from.  If no key is
  83.     pressed before the delay ends, the first partition marked as
  84.     "active" is used.  If no partition is marked as active, the
  85.     boot menu is presented without delay, as if a key were struck.
  86.     In essence, this program interprets the "active" mark (if
  87.     present) as a default choice indicator.
  88.  
  89.     Once a partition has been selected this program displays the
  90.     selected partition number and loads its secondary boot
  91.     program.  Errors are printed if (1) the selected partition is
  92.     empty, (2) the secondary boot program lacks a valid signature,
  93.     or (3) an error occurs while reading the secondary boot sector.
  94.  
  95.     Installation:
  96.     ------------
  97.     The "pfdisk" utility included with this program simplifies
  98.     installation of BOOTAUTO into the primary boot sector.
  99.     Instructions for using "pfdisk" are in the pfdisk.doc file.
  100.  
  101.     Limitations:
  102.     -----------
  103.     Names in the boot menu:
  104.  
  105.     BOOTMENU and BOOTAUTO contain a name table that is used to
  106.     generate the boot menu.  This name table is recognized (using
  107.     a signature) and updated by pfdisk but not by other fdisk
  108.     programs. If another fdisk program is used to modify the
  109.     partition table, the name table may be left with misleading
  110.     entries.  Note that pfdisk only updates the name field for any
  111.     entry when the entry is set using the optional name field, i.e:
  112.  
  113.         pfdisk> 1 4 0 127 MS-LOSS
  114.  
  115.     Furthermore, the name supplied as the fourth arg. is truncated
  116.     to eight characters.  (Space is tight in the boot sector.)
  117.  
  118.     The signature which flags the presence of a name table is
  119.     written into any boot sector every time the name argument is
  120.     given in a partition setting command (1,2,3,4).  This
  121.     signature occupies locations 0x1A0 -- 0x1AD which does not
  122.     clobber anything used by any of: UNIX or DOS boot programs,
  123.     SpeedStor or WesternDigital Auto-configuring controllers.
  124.  
  125.     Booting inactive partitions:
  126.  
  127.     MS-DOS will boot from an inactive partition without needing
  128.     any modifications.  Unfortunately, some systems refuse to boot
  129.     from a partition which is not marked as active.
  130.  
  131.     ESIX (from Everex Systems) Sys.V Rel.3.2 will not (as shipped)
  132.     boot unless its partition is marked active.  Other versions of
  133.     Sys.V/386 are similar in this regard.  The easiest solution is
  134.     to mark the UNIX partition as active, and use BOOTMENU to
  135.     offer you a choice between DOS and UNIX.
  136.  
  137.     If you wish, it is also possible to patch UNIX so that it will
  138.     boot without demanding that its partition be marked active.
  139.     These patches (called "esix-boot") are available from the
  140.     author.  Send EMAIL to gwr@linus.mitre.org if you want them.
  141.  
  142. SHAR_EOF
  143. if test 3923 -ne "`wc -c < 'bootmenu.doc'`"
  144. then
  145.     echo shar: error transmitting "'bootmenu.doc'" '(should have been 3923 characters)'
  146. fi
  147. fi # end of overwriting check
  148. echo shar: extracting "'pfdisk.doc'" '(6755 characters)'
  149. if test -f 'pfdisk.doc'
  150. then
  151.     echo shar: will not over-write existing file "'pfdisk.doc'"
  152. else
  153. cat << \SHAR_EOF > 'pfdisk.doc'
  154.  
  155.  
  156.  
  157.  
  158.  
  159. PFDISK(8)          MAINTENANCE COMMANDS        PFDISK(8)
  160.  
  161.  
  162.  
  163.  
  164.  
  165. NAME
  166.     pfdisk - partition fixed disk
  167.  
  168. SYNOPSIS
  169.     pfdisk device
  170.  
  171. DESCRIPTION
  172.     pfdisk partitions the fixed disk identified as device  into  (at
  173.     most) four parts, each of which    may be independently loaded with
  174.     an operating system.  The actual name of device    depends     on  the
  175.     operating  system  in  use.   For ESIX (System V/386) the device
  176.     name is    either "/dev/rdsk/0s0" or "/dev/rdsk/1s0".   For  Minix,
  177.     it is "/dev/hd0" or "/dev/hd5".     For MS-DOS it is a single digit
  178.     (zero or one).
  179.  
  180.     pfdisk reads the hard disk partition table from     block    zero  of
  181.     device    into  memory  and allows the user to examine, modify, or
  182.     save the partition table.  A regular file may be used instead of
  183.     a  real     device    for testing purposes, though the device    geometry
  184.     must be    specified manually, and    some  systems  will  requrire  a
  185.     file-name argument with    the "R"    and "W"    commands (DOS, ESIX).
  186.  
  187.     The partition table on device is NOT modified unless  the  write
  188.     command    (W) is used with no argument.
  189.  
  190. USAGE
  191.   Commands
  192.     All pfdisk commands  consist  of  a  command  word  followed  by
  193.     optional  blank-separated command arguments.  Note that    only the
  194.     first letter of    a command word is significant (except  for  "wq"
  195.     and  "q!").  All command letters are accepted in either    upper or
  196.     lower case.  Numeric arguments are  specified  using  C     syntax.
  197.     Extra arguments    are silently ignored.
  198.  
  199.     The commands are:
  200.  
  201.     ?    Prints a command summary (help).
  202.  
  203.     1 sys_id first last sys_name
  204.         Set the    partition  table  entry     for  part  one,  using:
  205.         sys_id    as  its    system ID code,    first as the lowest num-
  206.         bered cylinder it uses,    last  as  the  highest    numbered
  207.         cylinder  it uses, and sys_name    (optional) as the system
  208.         name (in the menu name table).
  209.  
  210.     2|3|4 sys-id first last    sys-name
  211.         Similar    to 1 but sets partition     two,  three,  or  four,
  212.         respectively.
  213.  
  214.  
  215.  
  216.  
  217.  
  218. Release    1.3          Last change: Oct 1990            1
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. PFDISK(8)          MAINTENANCE COMMANDS        PFDISK(8)
  226.  
  227.  
  228.  
  229.  
  230.  
  231.     A number
  232.         Mark partition number as active    (so it will be used  for
  233.         booting).   If    number    is  zero,  no  partition will be
  234.         active.
  235.  
  236.     G cylinders heads sectors
  237.         Inform pfdisk what the geometry    of the device is.
  238.  
  239.     I    Print a    summary    of the known ID    codes.
  240.  
  241.     L    List the partition table.  See Output Format below.
  242.  
  243.     Q    Quit without saving.  If the memory copy of  the  parti-
  244.         tion  table  was  modified, a warning will be issued and
  245.         the command ignored.
  246.  
  247.     Q!    Quit, even if the memory copy of the partition table was
  248.         not saved.
  249.  
  250.     R file-name
  251.         Read boot sector from  file-name  (if  given)  otherwise
  252.         read from device.
  253.  
  254.     W file-name
  255.         Write boot sector to  file-name.  (if  given)  otherwise
  256.         write to device.
  257.  
  258.     WQ    Same as    "write"    followed by "quit".
  259.  
  260.     #    This line is a comment (to be ignored).
  261.  
  262.   Output Format
  263.     Here is    a sample of the    output from the    L command:
  264.  
  265.     # Partition table on device: /dev/rdsk/0s0
  266.     geometry 1222 15 34 (cyls heads    sectors)
  267.     #  ID  First(cyl)  Last(cyl)  Name     # start,    length (sectors)
  268.     1   4       0        127          MS-LOSS  # 34, 65246
  269.     2 129     128        255          Minix    # 65280,    65280
  270.     3   0       0          0               # 0, 0
  271.     4  99     256       1220          ESIX     # 130560, 492150
  272.     # note:     last(4): phys=(1023,14,34) logical=(1220,14,34)
  273.     active:    4
  274.  
  275.     This output format is carefully    constructed so that  it     may  be
  276.     saved in a file     (by redirecting standard output) and later used
  277.     as input (by redirecting standard input).  On a    UNIX system, one
  278.     can save this output using the command:
  279.  
  280.  
  281.  
  282.  
  283.  
  284. Release    1.3          Last change: Oct 1990            2
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. PFDISK(8)          MAINTENANCE COMMANDS        PFDISK(8)
  292.  
  293.  
  294.  
  295.  
  296.  
  297.         (echo L) | pfdisk device-name >    save-file
  298.  
  299.     save-file is a complete    record of the  partition  table.   On  a
  300.     UNIX system, one could use save-file to    re-initialize the parti-
  301.     tion table using the command:
  302.  
  303.         (cat save-file ; echo wq) | pfdisk device-name
  304.  
  305.     Consistency of each partition table entry is checked  while  the
  306.     table is listed.  Any inconsistencies discovered are reported in
  307.     a commentary note as shown above.
  308.  
  309.   Physical vs. Logical
  310.     Each partition table entry has both "physical" and  a  "logical"
  311.     fields.      The  physical     fields     specify  the lowest and highest
  312.     cylinder,head,sector combinations to be    used in    that  partition.
  313.     The  logical  start  field has the total number    of sectors which
  314.     precede    this partition,    and the    logical     length     field    has  the
  315.     total  number  of  sectors  contained  in this partition.  These
  316.     fields should be self consistent unless    the disk has  more  than
  317.     1024 cylinders.
  318.  
  319.     The physical cylinder fields are only ten-bits wide so the  con-
  320.     tents are limited to 1023. The logical sector fields are 32 bits
  321.     wide and always    show the true logical beginning     and  length  of
  322.     the partition.    Generally, the physical    start field is used only
  323.     to locate the secondary    boot sector, and the logical  start  and
  324.     length fields are used to actually delimit the partition used by
  325.     a particular system.
  326.  
  327.   Partition Names
  328.     The Name field in the partition    table is  treated  specially  if
  329.     the  bootmenu  program    is installed in    the primary boot sector.
  330.     (See the file bootmenu.doc for    more  information.)  pfdisk  can
  331.     recognize  the    name  table  used  by bootmenu and will    show the
  332.     actual names present in    that name table.  If any other boot pro-
  333.     gram  is  used    then  the  Name     field    reflects the result of a
  334.     table-lookup of    the system ID.
  335.  
  336.     If you provide a name when  setting  any  partition  entry,  the
  337.     boot-sector  is     marked    as using a name    table, so that on subse-
  338.     quent uses of pfdisk you will see the partition    names  you  have
  339.     specified.
  340.  
  341.   Boot program replacement
  342.     You can    replace    the boot program in  your  boot     sector     without
  343.     affecting  the    partition  table  by  using  pfdisk  as    follows.
  344.     First, (as always) save    a copy of the current boot sector (on  a
  345.  
  346.  
  347.  
  348.  
  349.  
  350. Release    1.3          Last change: Oct 1990            3
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. PFDISK(8)          MAINTENANCE COMMANDS        PFDISK(8)
  358.  
  359.  
  360.  
  361.  
  362.  
  363.     floppy)    using the "W file" command.  Then, use the "R file" com-
  364.     mand to    read the new boot program.  If the boot    program    read  in
  365.     is  less  than    446  bytes  long,  the    partition  table will be
  366.     unchanged.
  367.  
  368.     Unlike the DOS or UNIX fdisk programs, pfdisk has NO  boot  pro-
  369.     gram  compiled    into  its  executable image.  If you wish to use
  370.     pfdisk to partition a newly formatted hard disk, you must have a
  371.     boot  program image available to read in using the "r file" com-
  372.     mand.  Two boot    programs, "bootmenu.bin" and "bootauto.bin"  are
  373.     distributed  with  pfdisk  and    should    be found with its source
  374.     files.    See the    file bootmenu.doc for further information  about
  375.     these boot programs.
  376.  
  377. AUTHOR
  378.     Gordon W. Ross
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416. Release    1.3          Last change: Oct 1990            4
  417.  
  418. SHAR_EOF
  419. if test 6755 -ne "`wc -c < 'pfdisk.doc'`"
  420. then
  421.     echo shar: error transmitting "'pfdisk.doc'" '(should have been 6755 characters)'
  422. fi
  423. fi # end of overwriting check
  424. echo shar: extracting "'SStor.txt'" '(1041 characters)'
  425. if test -f 'SStor.txt'
  426. then
  427.     echo shar: will not over-write existing file "'SStor.txt'"
  428. else
  429. cat << \SHAR_EOF > 'SStor.txt'
  430.  
  431. Note: SpeedStor (sstor) modifies SEVERAL locations in the boot sector!
  432.  
  433. The SpeedStor manual says it does not modify locations 0xEA -- 0x17D
  434. BUT THEY LIE!  If you use the "Parameter Override" feature, "sstor"
  435. (evidently) puts the new disk parameters in locations 0xEA -- 0xF9.
  436.  
  437. If you install BOOTAUTO and then run sstor, using the parameter
  438. override feature, you will have clobbered the BOOTAUTO program in a
  439. way such that it hangs or repeats its menu when you make a selection!
  440. (Yes, I learned this the hard way...)
  441.  
  442. To get around this problem, I wrote a slimmed-down version of the boot
  443. program, called BOOTMENU, which has unused "holes" strategicly placed
  444. in the locations known to be clobbered by SpeedStor.  Though this
  445. version has the advantage of SpeedStor compatibility, it does not have
  446. the ability to do automatic, unattended reboots like BOOTAUTO can.
  447.  
  448. For future reference, also note that sstor will modify locations
  449. 0x17E -- 0x1BD if you create SpeedStor partitions.  To their credit,
  450. this is indeed mentioned in the manual.
  451.  
  452. SHAR_EOF
  453. if test 1041 -ne "`wc -c < 'SStor.txt'`"
  454. then
  455.     echo shar: error transmitting "'SStor.txt'" '(should have been 1041 characters)'
  456. fi
  457. fi # end of overwriting check
  458. echo shar: extracting "'bootmenu.asm'" '(5005 characters)'
  459. if test -f 'bootmenu.asm'
  460. then
  461.     echo shar: will not over-write existing file "'bootmenu.asm'"
  462. else
  463. cat << \SHAR_EOF > 'bootmenu.asm'
  464.     PAGE 60,132
  465. ;    bootmenu: BOOT Hard Disk Partition
  466. ;    by Gordon W. Ross, Aug 1990
  467. ;
  468. ;    See the file bootmenu.doc for user instructions.
  469. ;
  470. ;    This version of bootmenu is compatible with SpeedStor.
  471. ;    See the file sstor-bug.txt for the gory details.
  472. ;
  473. ;    The following is an outline of the program:
  474. ;
  475. ;    Relocate self from 0x7c00 to 0x0600
  476. ;    Display partition menu
  477. ;    Prompt for and read user selection
  478. ;
  479. ;    Boot from the selected partition:
  480. ;    (was selected by user, or was active)
  481. ;    Read first sector of selected partition into 0x7c00
  482. ;    Verify good second-stage boot sector (magic word)
  483. ;    Set-up correct register values and jump to it.
  484. ;
  485.  
  486. CODEORG    equ 0600h    ; offset of this code in code seg
  487. ; All values computed from offsets in codeseg need to be
  488. ; adjusted by adding CODEORG to each.  The obvious method,
  489. ; using "org CODEORG" causes MASM/LINK to fill in the space.
  490.  
  491. codeseg    segment
  492.     assume cs:codeseg, ds:codeseg
  493.  
  494. ; Initial program entry point
  495. ; (Assembler is told this is at offset zero.)
  496.  
  497. main:
  498.     ; Set up the stack
  499.     xor    ax,ax
  500.     mov    si,7C00h    ; just before load location
  501.     cli
  502.     mov    ss,ax
  503.     mov    sp,si
  504.     sti
  505.  
  506. ; Relocate this code from 0:7C00h to 0:CODEORG
  507.     mov    ds,ax
  508.     mov    es,ax
  509.     mov    si,7C00h    ; where this program is initially loaded
  510.     mov    di,CODEORG
  511.     mov    cx,0100h
  512.     cld
  513.     rep    movsw
  514.  
  515. ; Jump to relocated code (0:CODEORG)
  516.     jmp    far ptr begin1
  517. begin    equ    $    ; The above jump lands here.
  518.  
  519. ; Print partition menu from name table
  520. menu:
  521.     call    putnl        ; print newline
  522.     mov    si, offset pnames ; no org fix-up here!
  523.     mov    al, '1'
  524. prname:
  525.     push    si
  526.     push    ax
  527.  
  528.     call    putc
  529.     mov    al,' '
  530.     call    putc
  531.     mov    cx,8        ; maximum name length
  532.     call    putn
  533.     call    putnl
  534.  
  535.     pop    ax
  536.     pop    si
  537.     add    si,8
  538.     inc    al
  539.     cmp    al,'4'
  540.     jbe    prname
  541.  
  542. ; Prompt for and read user selection
  543. select:
  544.     call    putnl    ; print prompt
  545.     mov    si, offset prompt + CODEORG
  546.     call    puts
  547.  
  548.     mov    ah,0    ; Read a keystroke and print it
  549.     int    16h
  550.     push    ax
  551.     call    putc
  552.     call    putnl
  553.     pop    ax
  554.  
  555.     sub    al,'1'    ; range check and convert to index
  556.     cmp    al,04
  557.     jnb    select
  558.  
  559. boot:
  560. ; Boot from the selected partition.
  561. ; On entry to this section:  AL = index of ptable element
  562.  
  563.     ; get address of ptable element (si = & ptable[AL])
  564.     mov    si, offset ptable ; no org fix-up here
  565.     mov    cl,16    ; size of array element
  566.     mul    cl        ; ax = al * cl
  567.     add    si,ax
  568.  
  569. ; Check for valid system ID (non-zero)
  570.  
  571.     mov    al,[si+4]
  572.     cmp    al,0
  573.     jnz    id_ok
  574.     mov    si, offset msgempty + CODEORG
  575.     jmp    error
  576. id_ok:
  577.  
  578. ; Read first sector of selected partition into 0x7c00
  579. ; Also, mark this entry active (in RAM only) in case the
  580. ; secondary boot program looks at it (which it may).
  581.  
  582.     mov    al,80h    ; active flag
  583.     mov    [si], al
  584.     mov    cx,5    ; retry count
  585. retry:    push    cx
  586.     mov    dx,[si]    ; drive, head
  587.     mov    cx,[si+2]    ; cyl, sector
  588.     mov    bx,7C00h    ; destination (es=0)
  589.     mov    ax,0201h    ; BIOS read one sector
  590.     int    13h
  591.     jnc    rd_ok
  592.     xor    ax,ax    ; reset disk
  593.     int    13h
  594.     pop    cx
  595.     loop    retry
  596.     mov    si, offset msgread + CODEORG
  597.     jmp    error
  598. rd_ok:    pop    cx
  599.  
  600. ; Check for valid magic number in secondary boot sector
  601.     mov    ax, 0AA55h
  602.     assume    ds:seg0        ; Actually, codeseg == seg0
  603.     cmp    ax, magic2
  604.     assume    ds:codeseg
  605.     jz    magic_ok
  606.     mov    si, offset msginvalid + CODEORG
  607.     jmp    error
  608. magic_ok:
  609.  
  610. ; Make sure ds:si points to the booted partition, and
  611. ; Jump to the secondary boot program.
  612.     jmp    far ptr begin2
  613.  
  614. ; Jump here with si=error-message
  615. error:
  616.     call    puts
  617.     call    putnl
  618.     jmp    menu
  619.  
  620. ;*************************************************************
  621. ; Subroutines
  622. ;*************************************************************
  623. CR    EQU    13
  624. LF    EQU    10
  625. TAB    EQU     9
  626.  
  627. putc    proc    near        ; print char in AL
  628.     mov    ah, 0Eh        ; uses: ax, bx
  629.     mov    bx, 07
  630.     int    10h
  631.     ret
  632. putc    endp
  633.  
  634. putnl    proc    near        ; print a newline
  635.     mov    al, CR        ; uses: ax, bx
  636.     call    putc
  637.     mov    al, LF
  638.     call    putc
  639.     ret
  640. putnl    endp
  641.  
  642. puts    proc    near        ; print string at address SI
  643.     mov    cx,80        ; Stop at null or CX chars
  644. putn:    lodsb            ; uses: ax, bx, cx, si
  645.     cmp    al,0
  646.     jz    puts_e
  647.     push    cx
  648.     call    putc
  649.     pop    cx
  650.     loop    putn
  651. puts_e:    ret
  652. puts    endp
  653.  
  654. ;**********************************************************
  655. ; A little space here makes this program live happily with
  656. ; SpeedStor, which wants to write type-override stuff here.
  657. ;**********************************************************
  658.  
  659.     org    100h
  660. ;**********************************************************
  661. ; Strings
  662. ;**********************************************************
  663.  
  664. prompt        db    "Boot partition? (1-4) ",0
  665. msgempty    db    "Empty!",0
  666. msgread        db    "Read error!",0
  667. msginvalid    db    "Invalid!",0
  668.  
  669. codeseg    ends
  670.  
  671. ; Declares some offsets in segment zero
  672. seg0    segment    at 0
  673.  
  674.     org    CODEORG + (offset begin - offset main)
  675. begin1    equ    $
  676.  
  677. ; Here is the name table used for the partition menu.
  678. ; The accompanying fdisk program updates this table.
  679.     org    CODEORG + 180h
  680. pnames    db    32 dup(?)
  681.  
  682. ; The locations after 1AE are (reportedly) used by some
  683. ; Western Digital controllers in "auto-configure" mode.
  684. ; Don't put anything critical between here and ptable.
  685.  
  686. ; Here is the partition table
  687.     org    CODEORG + 1BEh
  688. ptable    db    (4 * 16) dup(?)
  689.  
  690. ; Here is where the secondary boot sector is loaded.
  691.     org    7C00h
  692. begin2    equ    $
  693.     org    7DFEh
  694. magic2    dw    ?
  695. seg0    ends
  696.  
  697.     end    main
  698. SHAR_EOF
  699. if test 5005 -ne "`wc -c < 'bootmenu.asm'`"
  700. then
  701.     echo shar: error transmitting "'bootmenu.asm'" '(should have been 5005 characters)'
  702. fi
  703. fi # end of overwriting check
  704. echo shar: extracting "'bootauto.asm'" '(6427 characters)'
  705. if test -f 'bootauto.asm'
  706. then
  707.     echo shar: will not over-write existing file "'bootauto.asm'"
  708. else
  709. cat << \SHAR_EOF > 'bootauto.asm'
  710.     PAGE 60,132
  711. ;    bootauto:  Auto-boot version of BOOTMENU program
  712. ;    by Gordon W. Ross, Aug 1990
  713. ;
  714. ;    See the file bootmenu.doc for user instructions.
  715. ;
  716. ;    The following is an outline of the program:
  717. ;
  718. ;    Relocate self from 0x7C00 to 0x0600
  719. ;    Display message "Booting from HD0,"
  720. ;    Search partition table for an active entry
  721. ;    If an active partition is found,
  722. ;        Delay while watching for key press (5 sec.)
  723. ;        If (key pressed) GOTO menu:
  724. ;        Else GOTO boot:
  725. ;        EndIf
  726. ;    Else (no active partition)
  727. ; menu:        Display partition menu
  728. ;        Prompt for and read user selection
  729. ;    EndIf
  730. ; boot:    Boot from the selected partition:
  731. ;    (was selected by user, or was active)
  732. ;    Read first sector of selected partition into 0x7c00
  733. ;    Verify good second-stage boot sector (magic word)
  734. ;    Set-up correct register values and jump to it.
  735. ;    If (Errors during boot) { complain; GOTO menu: }
  736. ;
  737.  
  738. DELAY    equ    5*18    ; in ticks (1/18 sec.)
  739. CODEORG    equ 0600h    ; offset of this code in code seg
  740. ; All values computed from offsets in codeseg need to be
  741. ; adjusted by adding CODEORG to each.  The obvious method,
  742. ; using "org CODEORG" causes MASM/LINK to fill in the space.
  743.  
  744. codeseg    segment
  745.     assume cs:codeseg, ds:codeseg
  746.  
  747. ; Initial program entry point
  748. ; (Assembler is told this is at offset zero.)
  749.  
  750. main:
  751.     ; Set up the stack
  752.     xor    ax,ax
  753.     mov    si,7C00h    ; just before load location
  754.     cli
  755.     mov    ss,ax
  756.     mov    sp,si
  757.     sti
  758.  
  759. ; Relocate this code from 0:7C00h to 0:CODEORG
  760.     mov    ds,ax
  761.     mov    es,ax
  762.     mov    si,7C00h    ; where this program is initially loaded
  763.     mov    di,CODEORG
  764.     mov    cx,0100h
  765.     cld
  766.     rep    movsw
  767.  
  768. ; Jump to relocated code (0:CODEORG)
  769.     jmp    far ptr begin1
  770. begin    equ    $
  771.     mov    bp,sp    ; frame pointer = 0x7C00
  772.     sub    sp,4
  773. ; 2 words of local storage:
  774. ;    [bp-2] = ptable index [0-3]
  775. ;    [bp-4] = temporary value
  776.  
  777. ; Display message "Boot device: HD0"
  778.     mov    si, offset bootdev + CODEORG
  779.     call    puts
  780.  
  781. ; Search partition table for an active entry
  782.     mov    al,0
  783. search:
  784.     call    addr_pt    ; si = & ptable[AL]
  785.     mov    DL,[si]
  786.     cmp    DL,80h
  787.     jz    found
  788.     inc    al
  789.     cmp    al,04
  790.     jb    search
  791. ; Active partition not found
  792.     jmp    menu
  793.  
  794. found:    ; Found a partition marked active.
  795.     mov    [bp-2],ax    ; Save the ptable array index
  796.  
  797. ; Delay while watching for key press (2 sec.)
  798. ; Get start time, compute end time.
  799.     mov    ah,00
  800.     int    1Ah        ; BIOS get time of day
  801.     add    dx, DELAY    ; compute end time
  802.     mov    [bp-4],dx    ; save expiration time
  803.  
  804. ; Check for key press
  805. waitkey:
  806.     mov    ah,1
  807.     int    16h        ; BIOS Keyboard
  808.     jnz    menu    ; key pressed
  809.  
  810. ; Check for expiration of delay
  811.     mov    ah,00
  812.     int    1Ah        ; BIOS get time of day
  813.     sub    dx,[bp-4]
  814.     js    waitkey    ; delay not expired
  815.  
  816. ; Delay has expired, so boot the active partition
  817.     mov    al,','
  818.     call    putc
  819.     mov    ax,[bp-2]    ; ptable index
  820.     ; the index and newline are printed later
  821.     jmp    boot
  822.  
  823. ; Display partition menu
  824. menu:
  825.     mov    ah,1        ; flush input
  826.     int    16h
  827.     jz    fl_done
  828.     mov    ah,0
  829.     int    16h
  830.     jmp    menu
  831. fl_done:
  832.  
  833. ; Print partition menu from name table
  834.  
  835.     call    putnl        ; print newline
  836.     mov    si, offset pnames ; no org fix-up here
  837.     mov    al, '1'
  838. prname:
  839.     push    si
  840.     push    ax
  841.  
  842.     call    putc
  843.     mov    al,' '
  844.     call    putc
  845.     mov    cx,8        ; maximum name length
  846.     call    putn
  847.     call    putnl
  848.  
  849.     pop    ax
  850.     pop    si
  851.     add    si,8
  852.     inc    al
  853.     cmp    al,'4'
  854.     jbe    prname
  855.  
  856. ; Prompt for and read user selection
  857. select:
  858.     call    putnl
  859.     mov    si, offset prompt + CODEORG
  860.     call    puts
  861.     ; Read a key and convert it to a number
  862.     mov    ah,0
  863.     int    16h
  864.     sub    al,'1'
  865.     cmp    al,04
  866.     jnb    select
  867.     ; The key and a newline are printed below
  868.  
  869. boot:
  870. ; Boot from the selected partition.
  871. ; On entry to this section:  AL = index of ptable element
  872.  
  873.     ; get address of ptable element
  874.     call    addr_pt    ; si = & ptable[AL]
  875.  
  876.     ; print the parition index and a newline
  877.     add    al,'1'
  878.     call    putc
  879.     call    putnl
  880.  
  881. ; Check for valid system ID (non-zero)
  882.  
  883.     mov    al,[si+4]
  884.     cmp    al,0
  885.     jnz    id_ok
  886.     mov    si, offset msgempty + CODEORG
  887.     jmp    error
  888. id_ok:
  889.  
  890. ; Read first sector of selected partition into 0x7c00
  891. ; Also, mark this entry active (in RAM only) in case the
  892. ; secondary boot program looks at it (which it may).
  893.  
  894.     mov    al,80h    ; active flag
  895.     mov    [si], al
  896.     mov    cx,5    ; retry count
  897. retry:    push    cx
  898.     mov    dx,[si]    ; drive, head
  899.     mov    cx,[si+2]    ; cyl, sector
  900.     mov    bx,7C00h    ; destination (es=0)
  901.     mov    ax,0201h    ; BIOS read one sector
  902.     int    13h
  903.     jnc    rd_ok
  904.     xor    ax,ax    ; reset disk
  905.     int    13h
  906.     pop    cx
  907.     loop    retry
  908.     mov    si, offset msgread + CODEORG
  909.     jmp    error
  910. rd_ok:    pop    cx
  911.  
  912. ; Check for valid magic number in secondary boot sector
  913.     mov    ax, 0AA55h
  914.     assume    ds:seg0        ; Actually, codeseg == seg0
  915.     cmp    ax, magic2
  916.     assume    ds:codeseg
  917.     jz    magic_ok
  918.     mov    si, offset msginvalid + CODEORG
  919.     jmp    error
  920. magic_ok:
  921.  
  922. ; Make sure ds:si points to the booted partition, and
  923. ; Jump to the secondary boot program.
  924.     jmp    far ptr begin2
  925.  
  926. ; Jump here with si=error-message
  927. error:
  928.     call    puts
  929.     call    putnl
  930.     jmp    menu
  931.  
  932. ;*************************************************************
  933. ; Subroutines
  934. ;*************************************************************
  935. CR    EQU    13
  936. LF    EQU    10
  937. TAB    EQU     9
  938.  
  939. putc    proc    near        ; print char in AL
  940.     mov    ah, 0Eh        ; uses: ax, bx
  941.     mov    bx, 07
  942.     int    10h
  943.     ret
  944. putc    endp
  945.  
  946. putnl    proc    near        ; print a newline
  947.     mov    al, CR        ; uses: ax, bx
  948.     call    putc
  949.     mov    al, LF
  950.     call    putc
  951.     ret
  952. putnl    endp
  953.  
  954. puts    proc    near        ; print string at address SI
  955.     mov    cx,80        ; Stop at null or CX chars
  956. putn:    lodsb            ; uses: ax, bx, cx, si
  957.     cmp    al,0
  958.     jz    puts_e
  959.     push    cx
  960.     call    putc
  961.     pop    cx
  962.     loop    putn
  963. puts_e:    ret
  964. puts    endp
  965.  
  966. addr_pt    proc    near        ; set SI = address of ptable[al]
  967.     push    ax        ; uses: cx (but preserves ax)
  968.     mov    si, offset ptable ; no org fix-up here
  969.     mov    cl,16    ; size of array element
  970.     mul    cl        ; ax = al * cl
  971.     add    si,ax
  972.     pop    ax
  973.     ret
  974. addr_pt    endp
  975.  
  976. ;**********************************************************
  977. ; Strings
  978. ;**********************************************************
  979.  
  980. bootdev        db    "Boot device: hd0",0
  981. prompt        db    "Boot partition? (1-4) ",0
  982. msgempty    db    "Empty!",0
  983. msgread        db    "Read error!",0
  984. msginvalid    db    "Invalid!",0
  985.     org    180h    ; this pads the length (it seems)
  986. codeseg    ends
  987.  
  988. ; Declares some offsets in segment zero
  989. seg0    segment    at 0
  990.  
  991.     org    CODEORG + (offset begin - offset main)
  992. begin1    equ    $
  993.  
  994. ; Here is the name table used for the partition menu.
  995. ; The accompanying fdisk program updates this table.
  996.     org    CODEORG + 180h
  997. pnames    db    32 dup(?)
  998.  
  999. ; The locations after 1AE are (reportedly) used by some
  1000. ; Western Digital controllers in "auto-configure" mode.
  1001. ; Don't put anything critical between here and ptable.
  1002.  
  1003. ; Here is the partition table
  1004.     org    CODEORG + 1BEh
  1005. ptable    db    (4 * 16) dup(?)
  1006.  
  1007. ; Here is where the secondary boot sector is loaded.
  1008.     org    7C00h
  1009. begin2    equ    $
  1010.  
  1011.     org    7DFEh
  1012. magic2    dw    ?
  1013.  
  1014. seg0    ends
  1015.  
  1016.     end    main
  1017. SHAR_EOF
  1018. if test 6427 -ne "`wc -c < 'bootauto.asm'`"
  1019. then
  1020.     echo shar: error transmitting "'bootauto.asm'" '(should have been 6427 characters)'
  1021. fi
  1022. fi # end of overwriting check
  1023. echo shar: extracting "'asm2bin.bat'" '(262 characters)'
  1024. if test -f 'asm2bin.bat'
  1025. then
  1026.     echo shar: will not over-write existing file "'asm2bin.bat'"
  1027. else
  1028. cat << \SHAR_EOF > 'asm2bin.bat'
  1029. @echo off
  1030. REM This batch file builds file.bin from file.asm
  1031. if not arg%1==arg%1 goto arg
  1032. echo supply base name of file.asm, i.e. file
  1033. goto exit
  1034. :arg
  1035. echo on
  1036. masm %1,,;
  1037. link boot-hdp,;
  1038. @echo Ignore the 'no stack...' warning
  1039. del %1.obj
  1040. exe2bin %1
  1041. del %1.exe
  1042. :exit
  1043. SHAR_EOF
  1044. if test 262 -ne "`wc -c < 'asm2bin.bat'`"
  1045. then
  1046.     echo shar: error transmitting "'asm2bin.bat'" '(should have been 262 characters)'
  1047. fi
  1048. fi # end of overwriting check
  1049. echo shar: extracting "'make_msc.bat'" '(162 characters)'
  1050. if test -f 'make_msc.bat'
  1051. then
  1052.     echo shar: will not over-write existing file "'make_msc.bat'"
  1053. else
  1054. cat << \SHAR_EOF > 'make_msc.bat'
  1055. @echo This batch file uses Microsoft C to build pfdisk.exe
  1056. @echo Note that only SMALL model has been tested...
  1057. cl -AS -o pfdisk.exe pfdisk.c syscodes.c s_msdos.c
  1058. SHAR_EOF
  1059. if test 162 -ne "`wc -c < 'make_msc.bat'`"
  1060. then
  1061.     echo shar: error transmitting "'make_msc.bat'" '(should have been 162 characters)'
  1062. fi
  1063. fi # end of overwriting check
  1064. echo shar: extracting "'bootmenu.hex'" '(1177 characters)'
  1065. if test -f 'bootmenu.hex'
  1066. then
  1067.     echo shar: will not over-write existing file "'bootmenu.hex'"
  1068. else
  1069. cat << \SHAR_EOF > 'bootmenu.hex'
  1070.  33 C0 BE 00 7C FA 8E D0 8B E6 FB 8E D8 8E C0 BE
  1071.  00 7C BF 00 06 B9 00 01 FC F3 A5 EA 20 06 00 00
  1072.  E8 9E 00 BE 80 07 B0 31 56 50 E8 8C 00 B0 20 E8
  1073.  87 00 B9 08 00 E8 97 00 E8 86 00 58 5E 83 C6 08
  1074.  FE C0 3C 34 76 E2 E8 78 00 BE 00 07 E8 7D 00 B4
  1075.  00 CD 16 50 E8 62 00 E8 67 00 58 2C 31 3C 04 73
  1076.  E5 BE BE 07 B1 10 F6 E1 03 F0 8A 44 04 3C 00 75
  1077.  06 BE 17 07 EB 3A 90 B0 80 88 04 B9 05 00 51 8B
  1078.  14 8B 4C 02 BB 00 7C B8 01 02 CD 13 73 0D 33 C0
  1079.  CD 13 59 E2 E9 BE 1E 07 EB 16 90 59 B8 55 AA 3B
  1080.  06 FE 7D 74 06 BE 2A 07 EB 06 90 EA 00 7C 00 00
  1081.  E8 19 00 E8 0B 00 E9 67 FF B4 0E BB 07 00 CD 10
  1082.  C3 B0 0D E8 F3 FF B0 0A E8 EE FF C3 B9 50 00 AC
  1083.  3C 00 74 07 51 E8 E1 FF 59 E2 F4 C3 00 00 00 00
  1084.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1085.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1086.  42 6F 6F 74 20 70 61 72 74 69 74 69 6F 6E 3F 20
  1087.  28 31 2D 34 29 20 00 45 6D 70 74 79 21 00 52 65
  1088.  61 64 20 65 72 72 6F 72 21 00 49 6E 76 61 6C 69
  1089.  64 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1090.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1091.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1092.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1093.  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  1094.  
  1095. SHAR_EOF
  1096. if test 1177 -ne "`wc -c < 'bootmenu.hex'`"
  1097. then
  1098.     echo shar: error transmitting "'bootmenu.hex'" '(should have been 1177 characters)'
  1099. fi
  1100. fi # end of overwriting check
  1101. echo shar: extracting "'bootauto.hex'" '(1177 characters)'
  1102. if test -f 'bootauto.hex'
  1103. then
  1104.     echo shar: will not over-write existing file "'bootauto.hex'"
  1105. else
  1106. cat << \SHAR_EOF > 'bootauto.hex'
  1107.  33 C0 BE 00 7C FA 8E D0 8B E6 FB 8E D8 8E C0 BE
  1108.  00 7C BF 00 06 B9 00 01 FC F3 A5 EA 20 06 00 00
  1109.  8B EC 83 EC 04 BE 35 07 E8 EE 00 B0 00 E8 F9 00
  1110.  8A 14 80 FA 80 74 09 FE C0 3C 04 72 F0 EB 28 90
  1111.  89 46 FE B4 00 CD 1A 83 C2 5A 89 56 FC B4 01 CD
  1112.  16 75 14 B4 00 CD 1A 2B 56 FC 78 F1 B0 2C E8 A5
  1113.  00 8B 46 FE EB 46 90 B4 01 CD 16 74 06 B4 00 CD
  1114.  16 EB F4 E8 98 00 BE 80 07 B0 31 56 50 E8 86 00
  1115.  B0 20 E8 81 00 B9 08 00 E8 91 00 E8 80 00 58 5E
  1116.  83 C6 08 FE C0 3C 34 76 E2 E8 72 00 BE 46 07 E8
  1117.  77 00 B4 00 CD 16 2C 31 3C 04 73 ED E8 7A 00 04
  1118.  31 E8 52 00 E8 57 00 8A 44 04 3C 00 75 06 BE 5D
  1119.  07 EB 3A 90 B0 80 88 04 B9 05 00 51 8B 14 8B 4C
  1120.  02 BB 00 7C B8 01 02 CD 13 73 0D 33 C0 CD 13 59
  1121.  E2 E9 BE 64 07 EB 16 90 59 B8 55 AA 3B 06 FE 7D
  1122.  74 06 BE 70 07 EB 06 90 EA 00 7C 00 00 E8 19 00
  1123.  E8 0B 00 E9 61 FF B4 0E BB 07 00 CD 10 C3 B0 0D
  1124.  E8 F3 FF B0 0A E8 EE FF C3 B9 50 00 AC 3C 00 74
  1125.  07 51 E8 E1 FF 59 E2 F4 C3 50 BE BE 07 B1 10 F6
  1126.  E1 03 F0 58 C3 42 6F 6F 74 20 64 65 76 69 63 65
  1127.  3A 20 68 64 30 00 42 6F 6F 74 20 70 61 72 74 69
  1128.  74 69 6F 6E 3F 20 28 31 2D 34 29 20 00 45 6D 70
  1129.  74 79 21 00 52 65 61 64 20 65 72 72 6F 72 21 00
  1130.  49 6E 76 61 6C 69 64 21 00 00 00 00 00 00 00 00
  1131.  
  1132. SHAR_EOF
  1133. if test 1177 -ne "`wc -c < 'bootauto.hex'`"
  1134. then
  1135.     echo shar: error transmitting "'bootauto.hex'" '(should have been 1177 characters)'
  1136. fi
  1137. fi # end of overwriting check
  1138. echo shar: extracting "'hex2bin.c'" '(200 characters)'
  1139. if test -f 'hex2bin.c'
  1140. then
  1141.     echo shar: will not over-write existing file "'hex2bin.c'"
  1142. else
  1143. cat << \SHAR_EOF > 'hex2bin.c'
  1144. /*
  1145.  * hex2bin - a simple hex to binary converter
  1146.  */
  1147. #include <stdio.h>
  1148. main()
  1149. {
  1150.   int c;
  1151.  
  1152. #ifdef MSDOS
  1153.   setmode(stdout,O_BINARY);
  1154. #endif
  1155.  
  1156.   while (scanf("%x", &c) == 1)
  1157.     putchar(c);
  1158.   exit(0);
  1159. }
  1160. SHAR_EOF
  1161. if test 200 -ne "`wc -c < 'hex2bin.c'`"
  1162. then
  1163.     echo shar: error transmitting "'hex2bin.c'" '(should have been 200 characters)'
  1164. fi
  1165. fi # end of overwriting check
  1166. #    End of shell archive
  1167. exit 0
  1168.  
  1169.